-- 需要注意的是，此库不应限制是否在世界中

local b_util = {}
local e_util = require "libs/entutil"
local c_util= require "libs/calcutil"
local t_util = require "libs/tableutil"
-- local seg_time = TUNING.SEG_TIME--一格时间，默认30秒
local total_day_time = TUNING.TOTAL_DAY_TIME--一天时间，16格，8分钟
local buffs_data = {
    -- 电羊果冻
    electricattack = {
        image = "voltgoatjelly",
        duration = TUNING.BUFF_ELECTRICATTACK_DURATION,
        judge = {"voltgoatjelly"},
        describe = "攻击带电",
    },
    -- 蓝带鱼排
    moistureimmunity = {
        image = "frogfishbowl",
        duration = TUNING.BUFF_MOISTUREIMMUNITY_DURATION,
        judge = {"frogfishbowl"},
        describe = "免疫潮湿",
    },
    light = {
        image = "glowberrymousse",
        duration = TUNING.WORMLIGHT_DURATION * 4,
        judge = {
            "_spice_phosphor",
            "glowberrymousse", 
            "dish_fleshnapoleon", 
            wormlight = TUNING.WORMLIGHT_DURATION, 
            wormlight_lesser = TUNING.WORMLIGHT_DURATION * .25,
        },
        describe = "发光",
    },
    -- 蘑菇蛋糕
    sleepresistance = {
        image = "shroomcake",
        duration = TUNING.SLEEPRESISTBUFF_TIME,
        judge = {"shroomcake"},
        describe = "蘑菇慕斯",
    },
    -- 糖豆
    healthregen = { 
        image = "jellybean", 
        duration = TUNING.JELLYBEAN_DURATION,
        judge = {"jellybean"},
        describe = "彩虹糖",
    },
    sweettea = {
        image = "sweettea",
        duration = TUNING.SWEETTEA_DURATION,
        judge = {"sweettea"},
        describe = "知识增加",
    },
    -- 海难的咖啡
    coffee = {
        image = "cane", 
        duration = total_day_time / 2,
        judge = {"coffee"},
        describe = "咖啡加速",
    },
}
local spices = {
    -- 辣
    SPICE_CHILI = {
        image = "pepper",
        duration = TUNING.BUFF_ATTACK_DURATION,
        judge = {"_spice_chili"},
        describe = "火辣伤害",
    },
    -- 蒜
    SPICE_GARLIC = {
        image = "garlic",
        duration = TUNING.BUFF_PLAYERABSORPTION_DURATION,
        judge = {"_spice_garlic"},
        describe = "皮糙肉厚",
    },
    -- 甜
    SPICE_SUGAR = {
        image = "multitool_axe_pickaxe_pickaxeaxe",
        duration = TUNING.BUFF_WORKEFFECTIVENESS_DURATION,
        judge = {"_spice_sugar"},
        describe = "高效工作",
    },
}

function b_util:GetBuffs(foodname)
    local buffs = {}
    if type(foodname) == "string" and Prefabs[foodname] then
        local food = e_util:ClonePrefab(foodname)
        local edible = food and food.components.edible
        if edible then
            local spice = edible.spice
            if spice and type(spices[spice]) == "table" then
                buffs[spice] = t_util:MergeMap(spices[spice])
            end
            local temp = edible.temperaturedelta
            local dur = edible.temperatureduration
            if type(temp) == "number" and type(dur) == "number" and temp~=0 and dur~=0 then
                if temp > 0 then
                    buffs.HOT = {
                        duration = dur,
                        describe = "升温"..temp.."度",
                        image = "heatrock_fire5",
                    }
                else
                    buffs.COLD = {
                        duration = dur,
                        describe = "降温"..-temp.."度",
                        image = "icehat",
                    }
                end
            end
        end
        for buffname, buffdata in pairs(buffs_data)do
            for j_id, buffstr in pairs(buffdata.judge)do
                if type(j_id) == "number" then
                    if c_util:IsStrContains(foodname, buffstr)then
                        buffs[buffname] = t_util:MergeMap(buffdata)
                    end
                elseif j_id == foodname and type(buffstr)=="number" then
                    buffs[buffname] = t_util:MergeMap(buffdata)
                    buffs[buffname].duration = buffstr
                end 
            end
        end
    end
    return buffs
end

return b_util